﻿public class Solution {
    public int Candy(int[] ratings) 
    {
        int[] candyVec = new int[ratings.Length];
        Array.Fill(candyVec, 1);

        for (int i = 1; i < ratings.Length; i++)
        {
            if (ratings[i] > ratings[i - 1])
            {
                candyVec[i] = candyVec[i - 1] + 1;
            }
        }

        for (int i = ratings.Length-2; i >= 0 ; i--)
        {
            if (ratings[i] > ratings[i + 1])
            {
                candyVec[i] = Math.Max(candyVec[i], candyVec[i + 1] + 1);
            }
        }
        return candyVec.Sum();
    }

    public static void Main(string[] args)
    {
        int[] ratings = [1, 2, 2];
        Solution solution = new Solution();
        int res = solution.Candy(ratings);
        
        Console.WriteLine(res);
    }
}